<template>
  <!-- <div class="tab-bar-item" :class="{isActive:isActive}" @click="itemClick()"> -->
  <div class="tab-bar-item" :style="activeStyle" @click="itemClick()">
   <div v-if="!isActive"><slot name="item-icon"></slot></div>
   <div v-else><slot name="item-icon-active"></slot></div>
    <slot name="item-text"></slot>
    </div>
</template>

<script>
  export default {
    name: 'TabBarItem',
    props: {
      link: String,//路由path值
      activeColor: {//活跃状态color值
        type: String,
        default: 'red'
      }
    },
    data(){
      return {

      }
    },
    computed: {
      // 是否处于活跃
      isActive(){
        // 获取当前路由地址判断
        return this.$route.path.indexOf(this.link) !== -1;
      },
      // 判断活跃状态给予样式
      activeStyle(){
        return this.isActive ? {color:this.activeColor} : {};
      }
    },
    methods: {
      // 跳转到当前路由
      itemClick(){
        this.$router.replace(this.link)
      }
    }
  }
</script>

<style>
  .tab-bar-item {
    flex: 1;
    text-align: center;
    height: 49px;
    margin-top: 3px;
    margin-bottom: 2px;
    vertical-align: middle;
  }
  .tab-bar-item img {
    width: 24px;
    height: 24px;
  }
  /* .isActive {
    color: red;
  } */
</style>
